package com.ym.controller.patient.askDoctor;

import com.ym.common.constant.Constants;
import com.ym.core.annotation.ApiSign;
import com.ym.core.annotation.Log;
import com.ym.core.domain.APIResponse;
import com.ym.core.domain.BaseController;
import com.ym.core.shiro.ShiroUtil;
import com.ym.medical.domain.param.InquiryOrderParam;
import com.ym.medical.domain.vo.OrderVo;
import com.ym.medical.service.IDoctorServiceItemSV;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.Map;

/**
 * @author : 张文博
 * @date : 2019/5/27 10:48
 */
@Api("患者端-问医生-图文电话支付")
@RestController
@ApiSign
@RequestMapping(value = "/patient/ask/graphic",headers= Constants.Api.VERSION)
@Validated
public class GraphicTelephonePayController extends BaseController {

	private static final Logger LOGGER = LoggerFactory.getLogger(GraphicTelephonePayController.class);


	@Autowired
	private IDoctorServiceItemSV iDoctorServiceItemSV;

	@Log(dataBase = false, printBody = false)
	@ApiOperation("电话预约支付页(医生预约时间查询)")
	@GetMapping(value = "/phoneAppointmentTime")
	@ResponseBody
	public APIResponse<Map<String, Object>> phoneAppointmentTime(
			@ApiParam(name = "doctServId", value = "医生服务项id", required = true)
			@RequestParam Long doctServId) throws Exception {
		Map<String, Object> map = iDoctorServiceItemSV.phoneAppointmentTime(doctServId);
		return successData(map);

	}

	@Log
	@ApiOperation("电话图文预约支付页(订单生成)")
	@PostMapping(value = "/generatePhoneOrders")
	@ResponseBody
	public APIResponse<OrderVo> generateOrders(
			@ApiParam(name = "inquiryOrderModel", value = "订单对象", required = true)
			@RequestBody InquiryOrderParam inquiryOrderModel) throws Exception {
		Long userId = ShiroUtil.getLoginId();
		inquiryOrderModel.setUserId(userId);
		OrderVo order = iDoctorServiceItemSV.generateOrders(inquiryOrderModel);
		return successData(order);

	}

	@Log
	@ApiOperation("下单前判断")
	@GetMapping(value = "/order/limit")
	@ResponseBody
	public APIResponse samePatientLimit(
			@ApiParam(name = "patientId", value = "患者id", required = true)
					Long patientId,
			@ApiParam(name = "doctId", value = "医生id", required = false)
					Long doctId) {
		OrderVo orderVo = iDoctorServiceItemSV.samePatientLimit(patientId, doctId);
		if (orderVo != null) {
			return successData(orderVo);
		}
		return success();
	}


	@Log
	@ApiOperation("电话图文预约支付(应付款返回)")
	@PostMapping(value = "/payment/price")
	@ResponseBody
	public APIResponse<Map<String, BigDecimal>> couponUse(
			@ApiParam(name = "inquiryOrderModel", value = "订单对象", required = true)
			@RequestBody InquiryOrderParam inquiryOrderModel) {
		Map<String, BigDecimal> map = iDoctorServiceItemSV.couponUse(inquiryOrderModel);
		return successData(map);
	}


}
